/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
//import org.jboss.weld.logging.Category;

/**
 *
 * @author James
 */
@Entity
public class Cubes extends Item implements Serializable {
    private static final long serialVersionUID = 1L;
    //private int minimumNumOfBuyersToBeValid;
    private int  maxNumOfBuyers;
    private int  currentNumOfBuyers;
    private int  seq;
    private long startDate;
    private long endDate;
    @ManyToOne(cascade={CascadeType.PERSIST})
    private TermsAndConditions theTerm;
    
    public Cubes() {
        this.currentNumOfBuyers = 0;
        this.startDate          = 0;
        this.endDate            = 0;
        this.seq                = 0;
        this.setActive(false);
    }

    public void createCube(String name, String description, int type, int discount, int price, int additionalLoyaltyPoint, int maxNumberOfBuyers, boolean selling, ItemCategory theCategory, TermsAndConditions theTerm, List<Item> subItems) {
        this.name           = name;
        this.description    = description;
        this.type           = type;
        this.maxNumOfBuyers = maxNumberOfBuyers;
        this.selling        = selling; 
        this.theCategory    = theCategory;
        this.theTerm        = theTerm;
        ItemDetails details    = new ItemDetails();
        details.createItemDetails(discount, price, 0, additionalLoyaltyPoint, subItems);
        this.listOfItemDetails.add(details);
        this.latestItemDetails = details;
    }
    
    //Getters and Setters
    public int getCurrentNumOfBuyers() {
        return currentNumOfBuyers;
    }

    public void setCurrentNumOfBuyers(int currentNumOfBuyers) {
        this.currentNumOfBuyers = currentNumOfBuyers;
    }
    
    public int getSequence() {
        return seq;
    }
    
    public void setSequence(int seq) {
        this.seq = seq;
    }

    public long getEndDate() {
        return endDate;
    }

    public void setEndDate(long endDate) {
        this.endDate = endDate;
    }

    /*public int getMinimumNumOfBuyersToBeValid() {
        return minimumNumOfBuyersToBeValid;
    }

    public void setMinimumNumOfBuyersToBeValid(int minimumNumOfBuyersToBeValid) {
        this.minimumNumOfBuyersToBeValid = minimumNumOfBuyersToBeValid;
    }*/
    
    public int getMaxNumOfBuyers() {
        return maxNumOfBuyers;
    }

    public void setMaxNumOfBuyers(int maxNumOfBuyers) {
        this.maxNumOfBuyers = maxNumOfBuyers;
    }

    public long getStartDate() {
        return startDate;
    }

    public void setStartDate(long startDate) {
        this.startDate = startDate;
    }
    
    public void addVoucher(List<Voucher> listOfVouchers, Voucher voucher) {
        listOfVouchers.add(voucher);
    }

    public TermsAndConditions getTermsAndConditions() {
        return theTerm;
    }

    public void setTermsAndConditions(TermsAndConditions theTerm) {
        this.theTerm = theTerm;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cubes)) {
            return false;
        }
        Cubes other = (Cubes) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Cube[ id=" + id + " ]";
    }
    
}
